/**
 * 
 */
package ivan.cheng.tuqu.activity;

import ivan.cheng.tuqu.TuQulication;
import ivan.cheng.tuqu.util.LogUtil;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

/**
 * @author zhengfang
 *
 */
public abstract class UIActivity extends Activity 
{
	//protected TextView mTitle;
	protected TuQulication mApp;//应用程序的一个
	/**用户接受广播消息的接口,为所有类处理一些共有的广播,比如结束活动等*/
	public MessageReceiver mMessageReceiver = new MessageReceiver();
	public class MessageReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) 
		{
			OnBroadCastReceive(context, intent);
		}
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mApp = (TuQulication)getApplication();
		RegisterEvent();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(mMessageReceiver);
	}

	@Override
	protected void onPause() 
	{
		super.onPause();
		//MobclickAgent.onPause(this);
	}

	@Override
	protected void onResume() 
	{
		super.onResume();
		//MobclickAgent.onResume(this);
	}

	@Override
	protected void onStart() 
	{
		super.onStart();
		
	}

	@Override
	protected void onStop() 
	{
		super.onStop();
	}
	
	@Override
	public void onLowMemory() {
		super.onLowMemory();
	}
	
	protected void RegisterEvent() 
	{
		IntentFilter i = new IntentFilter();
		i.addAction("android.intent.action.PACKAGE_ADDED");
		i.addAction("android.intent.action.PACKAGE_REMOVED");
		i.addDataScheme("package");
		registerReceiver(mMessageReceiver, i);
	}
	
	protected void OnBroadCastReceive(Context context, Intent intent)
	{
		String action = intent.getAction();
		if (action.equals("android.intent.action.PACKAGE_ADDED")
			) 
		{
			String packageName = intent.getDataString().substring(8);
			LogUtil.d("PACKAGE_ADDED:" + packageName);
		}
		else if(action.equals("android.intent.action.PACKAGE_REMOVED"))
		{
			String packageName = intent.getDataString().substring(8);
			LogUtil.d("PACKAGE_REMOVED:" + packageName);
		}
	}
}
